﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using T3Task5;

namespace T5h
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //游戏名称获取
            string yx = this.textBox1.Text;
            //游戏类别获取
            string yxlb = this.comboBox1.Text;
            //游戏状态获取
            string state = "";
            if (rbStateDev.Checked)
            {
                state = rbStateDev.Text;
            }
            else if (rbStateTesr.Checked)
            {
                state = rbStateTesr.Text;
            }
            else if (rbStatePub.Checked)
            {
                state = rbStatePub.Text;
            }
            //游戏特色获取
            string tags = "";
            if (checkBox1.Checked)
            {
                tags += checkBox1.Text+"、";
            }
            else if (checkBox2.Checked)
            {
                tags += checkBox2.Text + "、";
            }
            else if (checkBox3.Checked)
            {
                tags += checkBox3.Text + "、";
            }
            else if (checkBox4.Checked)
            {
                tags += checkBox4.Text + "、";
            }
            else if (checkBox5.Checked)
            {
                tags += checkBox5.Text + "、";
            }
            //游戏添加
            //sql语句
            string sql = string.Format("insert Li(Customer,Anarchy,Style,Gamename)select '{0}', '{1}','{2}','{3}'", yx,yxlb,state,tags);
            bool result = DBHelper.GetNonQuery(sql);
            if (result)
            {
                MessageBox.Show("增加成功");
                this.Close();
                
            }
            else
            {
                MessageBox.Show("添加失败！");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Tag != null)
            {
                //获取组合框中显示的值
                string name = comboBox1.Text;
                //弹出消息框
                MessageBox.Show("您选择的专业是：" + name);
            }
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            
            try
            {
                string sql = string.Format("select Customer from Ln ");
                SqlDataReader da = DBHelper.Select(sql);
                while (da.Read())
                {
                    this.comboBox1.Items.AddRange(new object[] { da["Customer"] });//邦定数据
                }
                //设置组合框的DisPlayMember 属性
                comboBox1.DisplayMember = "da";
                //设置组合框的ValueMember属性
                comboBox1.ValueMember = "Customer";
                da.Close();
            }
            catch (Exception ex)
            {

                MessageBox.Show("出现错误！" + ex.Message);
            }
             
        }
    }
}
